<template>
  <div class="main">
    
      <div class="content">
        <el-row :gutter="10">
          <el-col :span="16">
                <div class="news-detail">
                    <h1 class="news-title">{{newsdetail.name}}</h1>
                    <p class="news-info">
                      <span>作者：{{newsdetail.author}}</span>
                      <span>{{newsdetail.createtime.slice(0,11)}}</span>
                    </p>
                    <p class="news-info">
                      <i>[摘要]：{{newsdetail.summary}}</i>
                    </p>
                    <div class="contenthtml" style="width:100%;display:none" v-html="newsdetail.contentList.list[0]"></div>                    
                    <div class="contenthtml" style="width:100%;" v-for="(item,index) in newsdetail.contentList.list" :key="index"
                                 v-if="item && newsitem == index" v-html="item"></div>
                    <div>
                      <!-- newslist -->
                      
                        <nuxt-link v-if="newsdetail.tagName.length != 0" v-for="(item,index) in newsdetail.tagName" :key="index" to="/newslist/touzi"><span class="tagitem">{{item}}</span></nuxt-link>
                      
                    </div>
                    <div style="text-align: right;overflow: hidden;padding-left: 500px;">
                       <!-- JiaThis Button BEGIN -->
                        <div class="jiathis_style_24x24">
                          <a class="jiathis_button_qzone"></a>
                          <a class="jiathis_button_tsina"></a>
                          <a class="jiathis_button_tqq"></a>
                          <a class="jiathis_button_weixin"></a>
                          <a class="jiathis_button_renren"></a>
                          <a href="http://www.jiathis.com/share" class="jiathis jiathis_txt jtico jtico_jiathis" target="_blank"></a>
                        </div>
                        <script type="text/javascript" src="http://v3.jiathis.com/code/jia.js" charset="utf-8"></script>
                        <!-- JiaThis Button END -->
                    </div>
                    <div class="fenye">
                      <el-pagination
                        layout="prev, pager, next"
                        :page-size="1"
                        @current-change="handleCurrentChange"
                        :total="newsdetail.contentList.count">
                      </el-pagination>
                    </div>
                     <contactus3></contactus3>
                       <!-- <div class="bdsharebuttonbox" style="margin-left: 500px;" data-tag="share_1">
                            <a class="bds_mshare" data-cmd="mshare"></a>
                            <a class="bds_qzone" data-cmd="qzone" href="#"></a>
                            <a class="bds_tsina" data-cmd="tsina"></a>
                            <a class="bds_baidu" data-cmd="baidu"></a>
                            <a class="bds_renren" data-cmd="renren"></a>
                            <a class="bds_tqq" data-cmd="tqq"></a>
                            <a class="bds_more" data-cmd="more">更多</a>
                      </div> -->
                </div>
                <div class="xiangguang">
                    <div class="title">
                      <h1>相关文章</h1>
                    </div>
                    <ul>
                      <li v-for="(item,index) in newlist" :key="index">
                        <nuxt-link :to="'/post/' + item.pid" target="_blank"><span class="newsname">{{item.name}}</span></nuxt-link>
                        <span>{{item.createtime.slice(0,11)}}</span>
                      </li>
                    </ul>
                </div>

          </el-col>
          <el-col :span="8">
                <contactus></contactus>
                <post1 :productlist="productlist"></post1>
                <detailnews :newslist="newlist"></detailnews>
           </el-col>
        </el-row>
      </div>
  </div>
</template>

<script>
import api from '../../../static/js/api.js'
import asyncApi from '../../../static/js/asyncApi.js'
import contactus from "../../../components/contactus";
import detailnews from "../../../components/detailnews";
import contactus3 from "../../../components/contactus3";
import post1 from "../../../components/post1";



export default {
  scrollToTop: true,
  data(){
    return{
        newsitem:0
    }
  },
  components: {
    contactus,
    detailnews,
    contactus3,
    post1
  },
  methods:{
    handleCurrentChange(val){
        this.newsitem = val-1
        this.gotoTop()
    },
    // goproduct(val){
    //     this.$router.push("/product/" + val)
    // },
    // getPostDetail(id){
    //   api.getPostDetail({id:id}).then((res)=>{
    //     this.newsdetail = res.data
    //   })
    // },
    // getproduct(){
    //   api.getProduct({page:"1",pageSize:"5"}).then((res)=>{
    //     this.productlist = res.data.list
    //   })
    // },
    menu() {
        this.scroll = document.documentElement.scrollTop || document.body.scrollTop;
          if(this.scroll >= 560){
            this.isshowfixednav = true
          }else{
             this.isshowfixednav = false
          }
    },
    gotoTop(){
       var scrollToptimer = setInterval(function () {
            var top = document.body.scrollTop || document.documentElement.scrollTop;
            var speed = top / 4;
            if (document.body.scrollTop!=0) {
                document.body.scrollTop -= speed;
            }else {
                document.documentElement.scrollTop -= speed;
            }
            if (top <= 30) {
                clearInterval(scrollToptimer);
            }
        }, 30); 
    },
    cofigShare(){
      window._bd_share_config = {
            common : {
               bdText : '天沁财富',
                bdDesc : '天沁财富',
                bdUrl : "http://www.tqcaifu.com/",
                bdPic : '自定义分享图片'
            },
            share : [{
                "bdSize" : 16
            }],
            slide : [{
                bdImg : 0,
                bdPos : "right",
                bdTop : 100
            }],
            image : [{
                viewType : 'list',
                viewPos : 'top',
                viewColor : 'black',
                viewSize : '16',
                viewList : ['qzone','tsina','huaban','tqq','renren']
            }],
            selectShare : [{
                "bdselectMiniList" : ['qzone','tqq','kaixin001','bdxc','tqf']
            }]
        }
    },
      mounted(){
      
          window.addEventListener('scroll', this.menu)

      }
  },
  mounted:function(){
      //this.cofigShare()
  },
  beforeCreate :function(){
          // var script = document.createElement ("script")
          // script.type = "text/javascript";
          // if (script.readyState){
          //     script.onreadystatechange = function(){
          //         if (script.readyState == "loaded" || script.readyState == "complete"){
          //             script.onreadystatechange = null;
          //         }
          //     };
          // } else {
          //     script.onload = function(){

          //     };
          // }
          // script.src = 'http://bdimg.share.baidu.com/static/api/js/share.js?cdnversion='+~(-new Date()/36e5);
          // document.getElementsByTagName("head")[0].appendChild(script);
  },
  async asyncData (context) {
    var id = parseInt(context.params.id);
    let [data1,data2,data3] = await Promise.all([
        asyncApi.asyncGetCategoryPost({categoryName: "投资策略",page: "1",pageSize: "4",orderBy:"weigh",orderByType:"desc"}),
        asyncApi.asyncgetPostDetail({id:id}),
        asyncApi.asyncgetProduct({page:"1",pageSize:"5"})
    ])
    return {
      newlist:data1.data.data.list,
      newsdetail:data2.data.data,
      productlist:data3.data.data.list
    }
 },
 head () {
    return {
      title: this.newsdetail.name,
      meta: [
         { hid:"keywords",name: 'keywords', content: '天沁财富' + this.newsdetail.categoryName },
         { hid:"description",name: 'description', content: this.newsdetail.summary }
      ]
    }
  }
};
</script>

<style scoped>
.tagitem{
  display: inline-block;
  height: 26px;
  text-align: center;
  padding: 0 10px;
  line-height: 26px;
  background: #cd9c54;
  color: white;
  font-size: 14px;
  margin-right: 20px;
}
.fenye{
  text-align: center;
} 
.xiangguang{
  background: white;
  padding: 20px;
}
.xiangguang .title{
  border-bottom: 1px solid #cd9c54;
}
.newsname{
  display: inline-block;
  width: 600px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.main .xiangguang h1{
  font-size: 16px;
  width: 150px;
  height: 40px;
  line-height: 40px;
  text-align: center;
  color: white;
  background: #cd9c54;
}
.xiangguang ul{
  padding:  0 30px;
}
.xiangguang ul li{
  display: flex;
  justify-content: space-between;
  height: 50px;
  line-height: 50px;
  font-size: 14px;
  color: #333;
}
.productDetali{
  height: 100px;
  border-bottom:1px solid #ccc; 
}
.productDetali p{
  color: #666;
}
.productDetali i{
  color: #b41d24;
}
.productDetali p span:nth-child(2){
  margin-left: 30px;
}
.productDetali h2{
  height: 50px;
  line-height: 50px;
  font-size: 18px;
  color: #333;
  font-weight: bolder;
  margin-top: 20px;
}
.news-detail{
  padding: 20px;
  background: white;
}
.news-title{
  text-align: center;
}
.news-info{
  padding: 20px 50px 0 50px;
}
.news-info span:nth-child(2){
  margin-left: 30px;
}
.news-info i{
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    width: 100%;
    overflow: hidden;
    display: inline-block;
    margin-bottom: 20px;
}
.contenthtml p{
  color: red !important;
}
.newsBox{
  background: white;
  padding: 20px;
  margin-top: 10px;
}
.newsBox h1 {
  color: #cd9c54 !important;
  font-size: 20px !important;
  height: 30px;
  line-height: 30px;
  border-bottom:1px solid #ccc; 
}

.main {
  width: 1200px;
  margin: 10px auto;
}
.main h1 {
  font-size: 20px;
  line-height: 30px;
  color: black;
  font-weight: normal;
}


</style>
